package org.dromara.hm.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.hm.domain.vo.HmOrderTransferHistoryVo;
import org.dromara.hm.domain.bo.HmOrderTransferHistoryBo;
import org.dromara.hm.service.IHmOrderTransferHistoryService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 订单归属转移历史
 *
 * @author Hzy
 * @date 2025-06-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hm/orderTransferHistory")
public class HmOrderTransferHistoryController extends BaseController {

    private final IHmOrderTransferHistoryService hmOrderTransferHistoryService;

    /**
     * 查询订单归属转移历史列表
     */
    @SaCheckPermission("hm:orderTransferHistory:list")
    @GetMapping("/list")
    public TableDataInfo<HmOrderTransferHistoryVo> list(HmOrderTransferHistoryBo bo, PageQuery pageQuery) {
        return hmOrderTransferHistoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出订单归属转移历史列表
     */
    @SaCheckPermission("hm:orderTransferHistory:export")
    @Log(title = "订单归属转移历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HmOrderTransferHistoryBo bo, HttpServletResponse response) {
        List<HmOrderTransferHistoryVo> list = hmOrderTransferHistoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单归属转移历史", HmOrderTransferHistoryVo.class, response);
    }

    /**
     * 获取订单归属转移历史详细信息
     *
     * @param orderTransferHistoryId 主键
     */
    @SaCheckPermission("hm:orderTransferHistory:query")
    @GetMapping("/{orderTransferHistoryId}")
    public R<HmOrderTransferHistoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long orderTransferHistoryId) {
        return R.ok(hmOrderTransferHistoryService.queryById(orderTransferHistoryId));
    }

    /**
     * 新增订单归属转移历史
     */
    @SaCheckPermission("hm:orderTransferHistory:add")
    @Log(title = "订单归属转移历史", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HmOrderTransferHistoryBo bo) {
        return toAjax(hmOrderTransferHistoryService.insertByBo(bo));
    }

    /**
     * 修改订单归属转移历史
     */
    @SaCheckPermission("hm:orderTransferHistory:edit")
    @Log(title = "订单归属转移历史", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HmOrderTransferHistoryBo bo) {
        return toAjax(hmOrderTransferHistoryService.updateByBo(bo));
    }

    /**
     * 删除订单归属转移历史
     *
     * @param orderTransferHistoryIds 主键串
     */
    @SaCheckPermission("hm:orderTransferHistory:remove")
    @Log(title = "订单归属转移历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderTransferHistoryIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] orderTransferHistoryIds) {
        return toAjax(hmOrderTransferHistoryService.deleteWithValidByIds(List.of(orderTransferHistoryIds), true));
    }
}
